#include "stm32f10x.h"                  // Device header
#include "OLED.h"
#include "Delay.h"
#include "Key.h"
#include "Encoder.h"
#include "Motor.h"

int8_t Speed = 0;

int main(void)
{
	OLED_Init();
	Encoder_Init();
	Motor_Init();
	Key_Init(RCC_APB2Periph_GPIOB, GPIOB, GPIO_Pin_1);
	OLED_ShowString(1, 1, "Speed=");
	
	while(1)
	{
		Speed += Get_Change();
		
		if (Speed > 100)
		{
			Speed = 100;
		}
		else if(Speed < -100)
		{
			Speed = -100;
		}
		
		if(Key_NO_OFF(GPIOB, GPIO_Pin_1) == 1)
		{
			Speed += 20;
			if(Speed > 100)
			{
				Speed = -100;
			}
		}
		Motor_SetSpeed(Speed);
		OLED_ShowSignedNum(1, 7, Speed, 3);
	}
}
